package com.demo.webflux.mongo;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration;
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;

import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoClients;

@Configuration
@EnableReactiveMongoRepositories(basePackageClasses = ArticleReactiveMongoRepository.class)
public class MongoConfig extends AbstractReactiveMongoConfiguration {

	@Bean
	@Override
	public MongoClient reactiveMongoClient() {
		return MongoClients.create("mongodb://127.0.0.1:27017/move_d?maxpoolsize=20&connecttimeoutms=500&sockettimeoutms=2000&maxidletimems=5000&maxlifetimems=300000&streamtype=netty");
	}

	@Override
	protected String getDatabaseName() {
		return "move_d";
	}

	@Override
	@Bean
	public ReactiveMongoTemplate reactiveMongoTemplate() throws Exception {
		return new ReactiveMongoTemplate(reactiveMongoClient(), getDatabaseName());
	}

}
